package com.panda.utils;

public class Finder {

    public static int findBody(char[] chars, int start) {

        int i = start;
        int bn = 0;
        out:
        for (; i < chars.length; i++) {

            switch (chars[i]) {

                case '{':

                    bn++;
                    break;
                case '}':

                    if (bn == 1) {
                        break out;
                    }
                    bn--;
                    break;
            }

        }

        if (i == chars.length) {
            return -1;
        }

        return i + 1;

    }

    //找参数
    public static int findParam(char[] chars, int start) {

        int i = start;

        int pn = 0;

        out:
        for (; i < chars.length; i++) {

            switch (chars[i]) {

                case '(':
                    pn++;
                    break;

                case ')':
                    if (pn == 1) {
                        break out;
                    }

                    pn--;
                    break;

            }
        }

        if (i == chars.length) {
            return -1;
        }

        return i + 1;

    }


}
